/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __M3508_H__
#define __M3508_H__

#ifdef __cplusplus
extern "C" {
#endif

/* USER CODE BEGIN Includes */
#include "main.h"
#include "cmsis_os.h"
#include "can.h"
#include "pid.h"
#include "usart.h"

/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */
#define M3508_CAN_HANDLE hcan2 // 使用的CAN句柄

typedef struct
{
    uint8_t id; // 电机ID (1-8)
    int16_t angle; // 电机转子角度 (范围：0 - 8191, 对应于 0 - 360°)
    int16_t rpm; // 电机转速 单位 RPM
    int16_t actual_current; // 实际转矩电流 (范围：-16384 ~ 16384, 对应于-20A ~ 20A)
    uint8_t temperature; // 电机温度 单位 °C
} M3508_FeedbackTypeDef;

extern M3508_FeedbackTypeDef m3508_feedback;
/* USER CODE END Private defines */

/* USER CODE BEGIN Prototypes */
void M3508_CAN_Start(void);
uint32_t M3508_SetCurrent(CAN_HandleTypeDef *hcan, uint8_t motor_id, int16_t goal_current);
void M3508_ReducerRpmControl_Init(float Kp, float Ki, float Kd, float deadband, float integral_limit);
void M3508_ReducerRpmControl_SetGoal(float goal_rpm);
int16_t M3508_ReducerRpm_Control(M3508_FeedbackTypeDef feedback);
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __M3508_H__ */

